﻿#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
#endregion

namespace pigs
{
    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    class MapLevelMenu : MenuScreen
    {
        ContentManager content;

        GameSettings settings;
        MenuEntry SelectLevelMenuEntry;
        MenuEntry NextLevelMenuEntry;
        MenuEntry exitMenuEntry;

        Texture2D currentMap;
        Texture2D skMap;
        Texture2D ontMap;
        Texture2D bcMap;

        string current;
        
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MapLevelMenu(ScreenManager screen, GameSettings set)
            : base("Levels")
        {
            settings = set;

            current = "Ontario";

            // Create our menu entries.
            SelectLevelMenuEntry = new MenuEntry("Play");
            NextLevelMenuEntry = new MenuEntry("Next Level");
            exitMenuEntry = new MenuEntry("Back");

            // Hook up menu event handlers.
            SelectLevelMenuEntry.Selected += SelectMenuEntrySelected;
            NextLevelMenuEntry.Selected += NextMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(NextLevelMenuEntry);
            MenuEntries.Add(SelectLevelMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            this.skMap = content.Load<Texture2D>("menu/maps/sk");
            this.ontMap = content.Load<Texture2D>("menu/maps/ont");
            this.bcMap = content.Load<Texture2D>("menu/maps/bc");
            this.currentMap = ontMap;
        }


        /// <summary>
        /// Event handler for when the Play Game menu entry is selected.
        /// </summary>L
        void SelectMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (current.Equals("Ontario")) LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new City(settings));
            else if (current.Equals("Saskatchewan")) LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new Prarie(settings));
            else if (current.Equals("British Columbia")) LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new Mountain(settings));
        }

        /// <summary>
        /// Event handler for when the Play Game menu entry is selected.
        /// </summary>L
        void NextMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (current.Equals("Ontario"))
            {
                current = "British Columbia";
                currentMap = bcMap;
            }
            else if (current.Equals("Saskatchewan"))
            {
                current = "Ontario";
                currentMap = ontMap;
            }
            else if (current.Equals("British Columbia"))
            {
                current = "Saskatchewan";
                currentMap = skMap;
            }
        }

        /// <summary>
        /// Draws the loading screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);

            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            Color color = Color.White * TransitionAlpha * TransitionAlpha;

            // Draw the text.
            spriteBatch.Begin();
            spriteBatch.Draw(currentMap, new Vector2((viewportSize.X - this.currentMap.Width) / 2, 0), color);
            spriteBatch.End();

            base.Draw(gameTime);
        }

    }
}
